package com.kateba.android.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import com.kateba.android.blueinput.Singleton;


public class RGSDK4
{
  private static final String LOG_TAG = "BlueInput::RGSDK4";
  private String m_szDeviceID;
  private String m_szNormON;
  private String m_szON;
  private String m_szProductID;
private String str1;
private String str3;
private String str2;
private int i;
private byte[] arrayOfByte;
private String str4;
private int k;
//private int m;

  private String Get8HDeviceID(String paramString)
  {
    Object localObject = null;
    try
    {
      MessageDigest localMessageDigest = MessageDigest.getInstance("MD5");
      localObject = localMessageDigest;
      str1 = "";
      if (localObject != null)
      {
        ((MessageDigest) localObject).update(paramString.getBytes(), 0, paramString.length());
        arrayOfByte = ((MessageDigest) localObject).digest();
        Singleton.getInstance().Debug("BlueInput::RGSDK4", "Ger8HDeviceID(" + paramString + " MD5 computed, resulting " + arrayOfByte.length + "bytes.");
        str3 = new String();
        i = 0;
        if (i >= arrayOfByte.length)
        {
          str4 = str3.toUpperCase();
          Singleton.getInstance().Debug("BlueInput::RGSDK4", "Get8HDeviceID(" + paramString + ") MD5(16)String=" + str4.toString() + " Length=" + str4.length());
         // if (str4.length() != 32)
          //  break label430;
          k = 0;
          if (k < 4)
//            break label298;
           str2 = str1.toUpperCase();
          Singleton.getInstance().Debug("BlueInput::RGSDK4", "Get8HDeviceID(" + paramString + ")=" + str2);
          return str2;
        }
      }
    }
    catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
    {
      while (true)
      {
        byte[] arrayOfByte = null;
        int i = 0;
        String str4 = null;
        int k = 0;
        localNoSuchAlgorithmException.printStackTrace();
      //  continue;
        int j = 0xFF & arrayOfByte[i];
        if (j <= 15)
          str3 = str3 + "0";
         str3 = str3 + Integer.toHexString(j);
        i++;
       // continue;
        	int m = Integer.parseInt(str4.substring(k * 2, 2 + k * 2), 16);
        for (int n = 0; ; n++)
        {
          if (n >= 4)
          {
            if (m <= 15)
              str1 = str1 + "0";
            str1 = str1 + Integer.toHexString(m);
            k++;
            break;
          }
          m ^= Integer.parseInt(str4.substring(2 * (n + k * 4), 2 + 2 * (n + k * 4)), 16);
        }
//        label430:
        	String str1 = "E0585359";
   //     continue;
        str1 = "E0585359";
      }
    }
	return str1;
  }

  // ERROR //
  private String NSK2DID(String paramString1, String paramString2)
  {
	return paramString2;
    // Byte code:
    //   0: invokestatic 52	com/teksoftco/android/blueinput/Singleton:getInstance	()Lcom/teksoftco/android/blueinput/Singleton;
    //   3: ldc 8
    //   5: new 54	java/lang/StringBuilder
    //   8: dup
    //   9: ldc 122
    //   11: invokespecial 59	java/lang/StringBuilder:<init>	(Ljava/lang/String;)V
    //   14: aload_1
    //   15: invokevirtual 63	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   18: ldc 124
    //   20: invokevirtual 63	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   23: aload_2
    //   24: invokevirtual 63	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   27: ldc 126
    //   29: invokevirtual 63	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   32: invokevirtual 74	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   35: invokevirtual 78	com/teksoftco/android/blueinput/Singleton:Debug	(Ljava/lang/String;Ljava/lang/String;)V
    //   38: aload_1
    //   39: invokevirtual 40	java/lang/String:length	()I
    //   42: bipush 16
    //   44: if_icmpeq +8 -> 52
    //   47: ldc 30
    //   49: astore_3
    //   50: aload_3
    //   51: areturn
    //   52: aload_2
    //   53: ldc 128
    //   55: if_acmpne +169 -> 224
    //   58: ldc 130
    //   60: astore 4
    //   62: ldc 132
    //   64: astore 5
    //   66: new 134	java/math/BigInteger
    //   69: dup
    //   70: aload_1
    //   71: bipush 16
    //   73: invokespecial 137	java/math/BigInteger:<init>	(Ljava/lang/String;I)V
    //   76: astore 6
    //   78: new 134	java/math/BigInteger
    //   81: dup
    //   82: aload 5
    //   84: bipush 10
    //   86: invokespecial 137	java/math/BigInteger:<init>	(Ljava/lang/String;I)V
    //   89: astore 7
    //   91: new 134	java/math/BigInteger
    //   94: dup
    //   95: aload 4
    //   97: bipush 10
    //   99: invokespecial 137	java/math/BigInteger:<init>	(Ljava/lang/String;I)V
    //   102: astore 8
    //   104: aload 6
    //   106: aload 7
    //   108: aload 8
    //   110: invokevirtual 141	java/math/BigInteger:modPow	(Ljava/math/BigInteger;Ljava/math/BigInteger;)Ljava/math/BigInteger;
    //   113: astore 9
    //   115: ldc 30
    //   117: astore 10
    //   119: invokestatic 52	com/teksoftco/android/blueinput/Singleton:getInstance	()Lcom/teksoftco/android/blueinput/Singleton;
    //   122: ldc 8
    //   124: new 54	java/lang/StringBuilder
    //   127: dup
    //   128: ldc 143
    //   130: invokespecial 59	java/lang/StringBuilder:<init>	(Ljava/lang/String;)V
    //   133: aload 9
    //   135: bipush 16
    //   137: invokevirtual 145	java/math/BigInteger:toString	(I)Ljava/lang/String;
    //   140: invokevirtual 63	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   143: invokevirtual 74	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   146: invokevirtual 78	com/teksoftco/android/blueinput/Singleton:Debug	(Ljava/lang/String;Ljava/lang/String;)V
    //   149: aload 9
    //   151: bipush 16
    //   153: invokevirtual 145	java/math/BigInteger:toString	(I)Ljava/lang/String;
    //   156: invokevirtual 40	java/lang/String:length	()I
    //   159: istore 11
    //   161: iload 11
    //   163: bipush 8
    //   165: if_icmplt +117 -> 282
    //   168: new 54	java/lang/StringBuilder
    //   171: dup
    //   172: aload 10
    //   174: invokestatic 98	java/lang/String:valueOf	(Ljava/lang/Object;)Ljava/lang/String;
    //   177: invokespecial 59	java/lang/StringBuilder:<init>	(Ljava/lang/String;)V
    //   180: aload 9
    //   182: bipush 16
    //   184: invokevirtual 145	java/math/BigInteger:toString	(I)Ljava/lang/String;
    //   187: invokevirtual 63	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   190: invokevirtual 74	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   193: invokevirtual 82	java/lang/String:toUpperCase	()Ljava/lang/String;
    //   196: astore_3
    //   197: invokestatic 52	com/teksoftco/android/blueinput/Singleton:getInstance	()Lcom/teksoftco/android/blueinput/Singleton;
    //   200: ldc 8
    //   202: new 54	java/lang/StringBuilder
    //   205: dup
    //   206: ldc 147
    //   208: invokespecial 59	java/lang/StringBuilder:<init>	(Ljava/lang/String;)V
    //   211: aload_3
    //   212: invokevirtual 63	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   215: invokevirtual 74	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   218: invokevirtual 78	com/teksoftco/android/blueinput/Singleton:Debug	(Ljava/lang/String;Ljava/lang/String;)V
    //   221: goto -171 -> 50
    //   224: aload_2
    //   225: ldc 149
    //   227: if_acmpne +14 -> 241
    //   230: ldc 151
    //   232: astore 4
    //   234: ldc 153
    //   236: astore 5
    //   238: goto -172 -> 66
    //   241: aload_2
    //   242: ldc 155
    //   244: if_acmpne +14 -> 258
    //   247: ldc 157
    //   249: astore 4
    //   251: ldc 159
    //   253: astore 5
    //   255: goto -189 -> 66
    //   258: ldc 30
    //   260: astore_3
    //   261: goto -211 -> 50
    //   264: astore 14
    //   266: invokestatic 52	com/teksoftco/android/blueinput/Singleton:getInstance	()Lcom/teksoftco/android/blueinput/Singleton;
    //   269: ldc 8
    //   271: ldc 161
    //   273: invokevirtual 78	com/teksoftco/android/blueinput/Singleton:Debug	(Ljava/lang/String;Ljava/lang/String;)V
    //   276: ldc 30
    //   278: astore_3
    //   279: goto -229 -> 50
    //   282: new 54	java/lang/StringBuilder
    //   285: dup
    //   286: aload 10
    //   288: invokestatic 98	java/lang/String:valueOf	(Ljava/lang/Object;)Ljava/lang/String;
    //   291: invokespecial 59	java/lang/StringBuilder:<init>	(Ljava/lang/String;)V
    //   294: ldc 100
    //   296: invokevirtual 63	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   299: invokevirtual 74	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   302: astore 10
    //   304: iinc 11 1
    //   307: goto -146 -> 161
    //   310: astore 13
    //   312: goto -46 -> 266
    //   315: astore 12
    //   317: goto -51 -> 266
    //
    // Exception table:
    //   from	to	target	type
    //   66	78	264	java/lang/NumberFormatException
    //   78	91	310	java/lang/NumberFormatException
    //   91	104	315	java/lang/NumberFormatException
  }

  private String NSKForm(String paramString)
  {
    Singleton.getInstance().Debug("BlueInput::RGSDK4", "NSKForm(" + paramString + ")");
    String str = null;
    if (paramString.length() != 24)
      str = "";
//    while (true)
//    {
////      return str;
//      str = paramString.substring(5, 9) + paramString.substring(10, 14) + paramString.substring(15, 19) + paramString.substring(20, 24);
//      Singleton.getInstance().Debug("BlueInput::RGSDK4", "NSKForm(" + paramString + ")=" + str);
//    }
	return str;
  }

  private String NormONString(String paramString)
  {
    String str1 = "";
    Object localObject;
    if (paramString == null)
    {
      localObject = str1;
      return (String) localObject;
    }
    for (int i = 0; ; i++)
    {
      if (i >= paramString.length())
      {
        String str2 = str1.toUpperCase();
        if (str2.length() == 0)
          str2 = "ABCDEFGH";
        Singleton.getInstance().Debug("BlueInput::RGSDK4", "NormONString(" + paramString + ")=[" + str2 + "]");
        localObject = str2;
        break;
      }
      if (((paramString.charAt(i) < 'A') || (paramString.charAt(i) > 'Z')) && ((paramString.charAt(i) < 'a') || (paramString.charAt(i) > 'z')) && ((paramString.charAt(i) < '0') || (paramString.charAt(i) > '9')) && (paramString.charAt(i) != '_') && (paramString.charAt(i) != '.'))
        continue;
      str1 = str1 + paramString.charAt(i);
    }
	return str1;
  }

  public boolean CheckUserInputKey(String paramString)
  {
    int i = 0;
    Singleton.getInstance().Debug("BlueInput::RGSDK4", "CheckUserInputKey(" + paramString + ") call");
    if ((paramString == null) || (paramString.length() == 0) || (paramString.length() != 24));
    while (true)
    {
//      return i;
      String str1 = NSKForm(paramString);
      String str2 = NSK2DID(str1, this.m_szProductID);
      Singleton.getInstance().Debug("BlueInput::RGSDK4", "CheckUserInputKey NSK=" + str1 + " DID(device)=" + this.m_szDeviceID + " UDID(from key)=" + str2 + " PID=" + this.m_szProductID);
      if (this.m_szDeviceID.compareTo(str2) != 0)
        continue;
      Singleton.getInstance();
      Singleton.getInstance().m_sett.setKey(str1);
      i = 1;
    }
  }

  public void InitRGSDK4(String paramString1, String paramString2)
  {
    Singleton.getInstance().Debug("BlueInput::RGSDK4", "InitRGSDK4(" + paramString1 + "," + paramString2 + ")");
    this.m_szON = paramString1;
    this.m_szNormON = NormONString(this.m_szON);
    this.m_szDeviceID = Get8HDeviceID(this.m_szNormON);
    this.m_szProductID = paramString2;
    Singleton.getInstance().Debug("BlueInput::RGSDK4", "InitRGSDK4 NormON=" + this.m_szON + " DID=" + this.m_szDeviceID);
  }

  public boolean IsRegistered()
  {
    Singleton.getInstance().Debug("BlueInput::RGSDK4", "IsRegistered call.");
    Singleton.getInstance();
    String str = NSK2DID(Singleton.getInstance().m_sett.getKey(), this.m_szProductID);
    Singleton.getInstance().Debug("BlueInput::RGSDK4", "IsRegistered UDID computed from file:" + str + " DID:" + this.m_szDeviceID);
    if (this.m_szDeviceID.compareTo(str) == 0);
    for (int i = 1; ; i = 0)
      return i==1?true:false;
  }
}